import manageService from "../service/manage";
import { codeFail, codeSuccess } from "./resultData";
import {Application} from "express";

export default function (app: Application) {
  app.get("/apple/manage/type", async (req, res) => {
    const type = Number(req.query.type);
    const data = await manageService.queryList(type);
    res.send(codeSuccess(data));
  });
  app.post("/apple/manage/type", async (req, res) => {
    const data = await manageService.insert(req.body.data);
    if (!data) {
      return res.send(codeFail("添加类型失败"));
    }
    res.send(codeSuccess(data));
  });
  app.delete("/apple/manage/type", async (req, res) => {
    const data = await manageService.deleteById(req.query.id);
    if (!data) {
      return res.send(codeFail("删除失败"));
    }
    res.send(codeSuccess());
  });

  app.put("/apple/manage/type", async (req, res) => {
    const data = await manageService.update(req.body);
    if (!data) {
      return res.send(codeFail("更新失败"));
    }
    res.send(codeSuccess());
  });
}
